package com.qsign.sfrz_android.activity.home.Model;

import android.content.Context;
import android.graphics.Bitmap;
import com.example.print_sdk.PrintUtil;
import com.example.print_sdk.enums.ALIGN_MODE;
import com.example.print_sdk.enums.MODE_ENLARGE;

import java.io.IOException;

/**
 * Created by moxiaomo
 * on 2020/4/1
 */
public class PrintContract {

    private String TAG=PrintContract.class.getName ();


    private Context mContext;
    private PrintUtil pUtil;

    public PrintContract() {
    }

    public PrintContract(Context context, PrintUtil printUtil) {
        this.mContext=context;
        this.pUtil = printUtil;
    }


    public void printInit() {
        try {
            pUtil.setEncoding ("GB2312");
            pUtil.printEnableCertificate (true);
            pUtil.printEnableMark (false);
            pUtil.printLanguage(15);
            pUtil.printEncode (3);
            pUtil.getVersion ();
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public void printLabel(int number) {
        try {
            pUtil.printState ();
            pUtil.printStartNumber (number);
            pUtil.printConcentration (25);
            pUtil.printAlignment (ALIGN_MODE.ALIGN_CENTER);

            pUtil.printTextBold (true);
            pUtil.printText("test test test test test");
            pUtil.printLine ();
            pUtil.printAlignment (ALIGN_MODE.ALIGN_LEFT);
            pUtil.printTextBold (false);
            pUtil.printLine ();
            pUtil.printText("test test test test test");
            pUtil.printLine ();
            pUtil.printText("test test test test test");
            pUtil.printLine ();
            pUtil.printAlignment (ALIGN_MODE.ALIGN_CENTER);
            pUtil.printLine ();
            pUtil.printBarcode ("123456789", 80, 2);
            pUtil.printLine ();
            pUtil.printGoToNextMark ();
            pUtil.printEndNumber ();
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public void printText(int number) {

        try {
            pUtil.printState ();
            pUtil.printStartNumber (number);
            pUtil.printConcentration (25);

            pUtil.printFontSize (MODE_ENLARGE.NORMAL);
            pUtil.printTextBold (true); // 是否加粗
            pUtil.printAlignment (ALIGN_MODE.ALIGN_LEFT); // 对齐方式
            pUtil.printText (SystemUtils.LanguageChange (mContext));
            pUtil.printTextBold (false); // 关闭加粗
            pUtil.printFontSize (MODE_ENLARGE.NORMAL); // 字体大小
            pUtil.printLine ();
            pUtil.printDashLine ();
            pUtil.printLine (2);
            pUtil.printAlignment (ALIGN_MODE.ALIGN_CENTER);
            pUtil.printBarcode ("123456", 80, 2);
            pUtil.printLine ();
            pUtil.printQR ("1234456", 200, 200);
            pUtil.printLine (2);

            pUtil.printEndNumber ();

        } catch (IOException e) {

        }
    }


    public void printQR(String text, int number) {
        try {
            pUtil.printState ();
            pUtil.printStartNumber (number);
            pUtil.printQR (text, 200, 200);
            pUtil.printLine (3);
            pUtil.printEndNumber ();
        } catch (IOException e) {
            e.printStackTrace ();
        }

    }

    public void printBarcode(String text, int number) {
        try {
//            pUtil.printState ();
//            pUtil.printStartNumber (number);
//            pUtil.printLine (3);
//            pUtil.printBarcode (text, 200, 300);
//            pUtil.printLine (3);
//            pUtil.printEndNumber ();

            pUtil.printEnableMark(true);//开启黑标检测
            pUtil.printState();//开启打印状态回调
            pUtil.printStartNumber(number);//一票一控头部
            pUtil.printConcentration(25);
            pUtil.printAlignment(ALIGN_MODE.ALIGN_CENTER);
            pUtil.printLine(1);
            if (text.length() > 12) {







































































                pUtil.printBarcode(text, 80, 1);
            } else {
                pUtil.printBarcode(text, 80, 2);
            }
            pUtil.printGoToNextMark();//走纸到下张标签
            pUtil.printEndNumber ();
        } catch (IOException e) {
            e.printStackTrace ();
        }

    }

    public void printImg(Bitmap bitmap) {
        try {
            pUtil.printState ();
            pUtil.printConcentration (39);
            pUtil.printLine ();
            pUtil.printBitmap2 (bitmap);
        } catch (IOException e) {
            e.printStackTrace ();
        }

    }


    public void printFeatureList() {
        try {
            pUtil.printState ();
            pUtil.printFeatureList ();
        } catch (IOException e) {
            e.printStackTrace ();
        }

    }

    public void printThai() {
        try {
            pUtil.printState ();
            pUtil.printConcentration (25);
            pUtil.printFontSize (MODE_ENLARGE.NORMAL);
            pUtil.printAlignment (ALIGN_MODE.ALIGN_LEFT); // 对齐方式
            pUtil.printText ("หลังจากการจัดกลุ่มหมายเลขในรูปภาพดิจิทัลที่เขียนด้วยลายมือ");
            pUtil.printLine ();
        } catch (IOException e) {
            e.printStackTrace ();
        }

    }


    public void setLanguage(int mode) {
        try {
            pUtil.printState ();
            pUtil.printLanguage (mode);
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public void printEnableMark(boolean bool) {
        try {
            pUtil.printState ();
            pUtil.printEnableMark (bool);
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public void printGoToNextMark() {
        try {
            pUtil.printState ();
            pUtil.printGoToNextMark ();
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public void resetPrint() {
        try {
            pUtil.printState ();
            pUtil.resetPrint ();
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }

    public void closeDev(){
        pUtil.closeDev ();
    }


}
